import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import "./plugins/element.js";
// 导入全局样式表
import "./assets/css/global.css";
//导入数据请求包
import axios from "axios";
//安装树形插件：npm i vue-table-with-tree-grid -S
//导入树形插件
import TreeTable from "vue-table-with-tree-grid";
//导入富文本编辑器
import VueQuillEditor from "vue-quill-editor";
//导入富文本编辑器的样式
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
//全局引入深拷贝
import _ from "lodash";
Vue.prototype._ = _;

//导入网络加载 NProgress 包对应的文件
import NProgress from "nprogress";
import "nprogress/nprogress.css";

//请求的根路径
axios.defaults.baseURL = "http://127.0.0.1:8888/api/private/v1/";
//axios请求拦截添加toke，保证拥有获取数据的权限
axios.interceptors.request.use((config) => {
  //在 request 拦截器中展示进度条 NProgress.start()
  NProgress.start();
  //console.log(config);
  //未请求头对象添加token验证的Authorization字段
  config.headers.Authorization = window.sessionStorage.getItem("token");
  return config;
});
//在response 拦截器中隐藏进度条 NProgress.done()
axios.interceptors.response.use((config) => {
  NProgress.done();
  return config;
});
Vue.prototype.$http = axios;

Vue.component("tree-table", TreeTable);

Vue.config.productionTip = false;

//注协全局格式化时间过滤器
//padStart(2,'0')作用是第一个参数规定时间多少位，
//第二个参数是当时间位数地狱规定位数是用该参数替换
Vue.filter("dateFormat", (originVal) => {
  const dt = new Date(originVal * 1000);
  const y = dt.getFullYear();
  const m = (dt.getMonth() + 1 + "").padStart(2, "0");
  const d = (dt.getDate() + "").padStart(2, "0");
  const hh = (dt.getHours() + "").padStart(2, "0");
  const mm = (dt.getMinutes() + "").padStart(2, "0");
  const ss = (dt.getSeconds() + "").padStart(2, "0");

  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
});

//全局注册富文本编辑器为全局可用的对象
Vue.use(VueQuillEditor);

new Vue({
  router,
  render: (h) => h(App),
}).$mount("#app");
